// 模拟数据 - 用于开发和测试

export const mockData = {
  // 登录凭证
  loginCredentials: {
    username: 'admin',
    password: '123456'
  },
  
  // 模拟登录令牌
  token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJleHAiOjE3Mjk2MDg0MDB9.some-random-signature',
  
  // 仪表盘数据
  dashboardStats: {
    articles: 24,
    categories: 6,
    tags: 12,
    views: 1256
  },
  
  // 图片分类数据
  imageCategories: [
    { id: 1, name: '文章配图', count: 8 },
    { id: 2, name: '头像', count: 2 },
    { id: 3, name: '封面', count: 3 },
    { id: 4, name: '其他', count: 2 }
  ],
  
  // 图片数据
  images: [
    {
      id: 1,
      name: 'vue-logo.png',
      url: 'https://vuejs.org/images/logo.png',
      size: 102400,
      format: 'png',
      width: 256,
      height: 256,
      uploadDate: '2023-06-15 10:30:00',
      categoryId: 1,
      category: { id: 1, name: '文章配图' }
    },
    {
      id: 2,
      name: 'react-logo.png',
      url: 'https://reactjs.org/favicon.ico',
      size: 51200,
      format: 'png',
      width: 128,
      height: 128,
      uploadDate: '2023-06-10 14:20:00',
      categoryId: 1,
      category: { id: 1, name: '文章配图' }
    },
    {
      id: 3,
      name: 'javascript-banner.jpg',
      url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/99/Unofficial_JavaScript_logo_2.svg/2048px-Unofficial_JavaScript_logo_2.svg.png',
      size: 2048000,
      format: 'jpg',
      width: 1920,
      height: 1080,
      uploadDate: '2023-06-05 09:45:00',
      categoryId: 3,
      category: { id: 3, name: '封面' }
    },
    {
      id: 4,
      name: 'css-grid-tutorial.png',
      url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/CSS3_logo_and_wordmark.svg/1200px-CSS3_logo_and_wordmark.svg.png',
      size: 1536000,
      format: 'png',
      width: 1200,
      height: 630,
      uploadDate: '2023-05-28 16:10:00',
      categoryId: 1,
      category: { id: 1, name: '文章配图' }
    },
    {
      id: 5,
      name: 'profile-avatar.jpg',
      url: 'https://api.dicebear.com/7.x/avataaars/svg?seed=user1',
      size: 256000,
      format: 'jpg',
      width: 512,
      height: 512,
      uploadDate: '2023-05-20 11:30:00',
      categoryId: 2,
      category: { id: 2, name: '头像' }
    },
    {
      id: 6,
      name: 'nodejs-icon.png',
      url: 'https://nodejs.org/static/images/logo.svg',
      size: 768000,
      format: 'png',
      width: 800,
      height: 800,
      uploadDate: '2023-05-15 15:40:00',
      categoryId: 1,
      category: { id: 1, name: '文章配图' }
    },
    {
      id: 7,
      name: 'database-diagram.png',
      url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Sql_data_base_with_logo.png/1200px-Sql_data_base_with_logo.png',
      size: 3072000,
      format: 'png',
      width: 1200,
      height: 800,
      uploadDate: '2023-05-10 10:15:00',
      categoryId: 4,
      category: { id: 4, name: '其他' }
    },
    {
      id: 8,
      name: 'docker-container.png',
      url: 'https://www.docker.com/wp-content/uploads/2022/03/Moby-logo.png',
      size: 1024000,
      format: 'png',
      width: 1000,
      height: 1000,
      uploadDate: '2023-05-05 09:30:00',
      categoryId: 1,
      category: { id: 1, name: '文章配图' }
    },
    {
      id: 9,
      name: 'cloud-computing.jpg',
      url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/b5/Cloud_computing.svg/1200px-Cloud_computing.svg.png',
      size: 2560000,
      format: 'jpg',
      width: 1200,
      height: 800,
      uploadDate: '2023-04-28 14:20:00',
      categoryId: 3,
      category: { id: 3, name: '封面' }
    },
    {
      id: 10,
      name: 'security-lock.png',
      url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Lock_font_awesome.svg/1024px-Lock_font_awesome.svg.png',
      size: 512000,
      format: 'png',
      width: 1024,
      height: 1024,
      uploadDate: '2023-04-20 16:45:00',
      categoryId: 4,
      category: { id: 4, name: '其他' }
    },
    {
      id: 11,
      name: 'analytics-chart.jpg',
      url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Pie_chart.svg/1200px-Pie_chart.svg.png',
      size: 1536000,
      format: 'jpg',
      width: 1200,
      height: 900,
      uploadDate: '2023-04-15 11:10:00',
      categoryId: 1,
      category: { id: 1, name: '文章配图' }
    },
    {
      id: 12,
      name: 'mobile-app.png',
      url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Smartphone_Icon.svg/1200px-Smartphone_Icon.svg.png',
      size: 768000,
      format: 'png',
      width: 1200,
      height: 1200,
      uploadDate: '2023-04-10 09:25:00',
      categoryId: 3,
      category: { id: 3, name: '封面' }
    }
  ],
  
  // 分类数据
  categories: [
    { id: 1, name: '前端开发', count: 12 },
    { id: 2, name: 'UI框架', count: 8 },
    { id: 3, name: '性能优化', count: 5 },
    { id: 4, name: 'JavaScript', count: 15 },
    { id: 5, name: 'TypeScript', count: 3 },
    { id: 6, name: 'Vue3', count: 4 }
  ],
  
  // 标签数据
  tags: [
    { id: 1, name: 'Vue3', count: 15 },
    { id: 2, name: 'React', count: 10 },
    { id: 3, name: 'TypeScript', count: 8 },
    { id: 4, name: 'JavaScript', count: 12 },
    { id: 5, name: 'CSS3', count: 6 },
    { id: 6, name: '性能优化', count: 5 },
    { id: 7, name: '组合式API', count: 4 },
    { id: 8, name: '响应式系统', count: 3 },
    { id: 9, name: 'Ant Design', count: 2 }
  ],
  
  // 文章列表数据
  articles: [
    {
      id: 1,
      title: 'Vue3组合式API深入解析',
      summary: '本文将深入探讨Vue3的组合式API，包括setup函数、ref、reactive等核心概念...',
      excerpt: '本文将深入探讨Vue3的组合式API，包括setup函数、ref、reactive等核心概念...',
      date: '2023-10-15',
      category: '前端开发',
      categoryId: 1,
      tags: ['Vue3', '组合式API'],
      tagIds: [1, 7],
      views: 345,
      status: 'published'
    },
    {
      id: 2,
      title: 'Ant Design Vue使用技巧分享',
      summary: '分享一些在项目中使用Ant Design Vue的实用技巧和最佳实践...',
      excerpt: '分享一些在项目中使用Ant Design Vue的实用技巧和最佳实践...',
      date: '2023-09-28',
      category: 'UI框架',
      categoryId: 2,
      tags: ['Ant Design', 'Vue'],
      tagIds: [9, 1],
      views: 230,
      status: 'published'
    },
    {
      id: 3,
      title: '前端性能优化实战',
      summary: '从网络请求、资源加载、渲染性能等多个角度讲解前端性能优化的方法...',
      excerpt: '从网络请求、资源加载、渲染性能等多个角度讲解前端性能优化的方法...',
      date: '2023-08-10',
      category: '性能优化',
      categoryId: 3,
      tags: ['性能优化', '前端'],
      tagIds: [6, 1],
      views: 456,
      status: 'published'
    },
    {
      id: 4,
      title: 'Vue3响应式系统原理解析',
      summary: '深入分析Vue3的响应式系统实现原理，包括Proxy的应用和响应式追踪机制...',
      excerpt: '深入分析Vue3的响应式系统实现原理，包括Proxy的应用和响应式追踪机制...',
      date: '2023-07-25',
      category: '前端开发',
      categoryId: 1,
      tags: ['Vue3', '响应式系统'],
      tagIds: [1, 8],
      views: 320,
      status: 'published'
    },
    {
      id: 5,
      title: 'Vue3性能优化实践指南',
      summary: '分享Vue3项目中常见的性能优化技巧和实践经验，让你的应用更流畅...',
      excerpt: '分享Vue3项目中常见的性能优化技巧和实践经验，让你的应用更流畅...',
      date: '2023-07-10',
      category: '性能优化',
      categoryId: 3,
      tags: ['Vue3', '性能优化'],
      tagIds: [1, 6],
      views: 289,
      status: 'published'
    },
    {
      id: 6,
      title: 'JavaScript异步编程详解',
      summary: '从回调函数到Promise，再到async/await，全面讲解JavaScript异步编程的演进...',
      excerpt: '从回调函数到Promise，再到async/await，全面讲解JavaScript异步编程的演进...',
      date: '2023-06-20',
      category: 'JavaScript',
      categoryId: 4,
      tags: ['JavaScript', '异步编程'],
      tagIds: [4, 10],
      views: 367,
      status: 'draft'
    }
  ],
  
  // 个人信息
  personalInfo: {
    name: 'Gulu Blog',
    title: '前端开发工程师',
    description: '专注于Vue.js生态系统开发，热衷于分享前端技术和最佳实践。',
    initials: 'GB',
    about: [
      '你好！我是一名充满热情的前端开发工程师，拥有多年的Web开发经验。我专注于使用现代前端技术构建高质量、高性能的Web应用。',
      '我热衷于学习新技术，并将其应用到实际项目中。同时，我也喜欢通过写作分享我的知识和经验，希望能够帮助到更多的开发者。',
      '在这个博客中，我会分享关于前端开发的各种知识，包括Vue.js、React、TypeScript、性能优化等方面的内容。'
    ],
    skills: [
      {
        name: 'Vue.js',
        progress: 95,
        description: '精通Vue.js框架，包括组合式API、响应式系统等。'
      },
      {
        name: 'React',
        progress: 85,
        description: '熟练使用React框架及其生态系统。'
      },
      {
        name: 'JavaScript/TypeScript',
        progress: 90,
        description: '精通JavaScript和TypeScript，掌握高级特性。'
      },
      {
        name: 'CSS3/SCSS',
        progress: 88,
        description: '熟练掌握CSS3和SCSS，能创建精美的界面。'
      },
      {
        name: 'Webpack/Vite',
        progress: 82,
        description: '熟悉前端构建工具，能优化项目构建流程。'
      }
    ],
    contact: [
      {
        type: 'email',
        label: '邮箱',
        value: 'contact@gulublog.com',
        href: 'mailto:contact@gulublog.com'
      },
      {
        type: 'github',
        label: 'GitHub',
        value: 'github.com/gulublog',
        href: 'https://github.com/gulublog'
      },
      {
        type: 'zhihu',
        label: '知乎',
        value: 'zhihu.com/people/gulublog',
        href: 'https://www.zhihu.com/people/gulublog'
      }
    ]
  },
  
  // 系统配置
  systemConfig: {
    siteName: 'Gulu Blog',
    description: '专注于前端技术分享的博客',
    keywords: 'Vue.js,React,JavaScript,前端开发',
    footerText: '© 2023 Gulu Blog. All rights reserved.',
    enableComments: true,
    enableAnalytics: true
  },
  
  // ICP备案配置
  icpConfig: {
    icpNumber: '京ICP备12345678号-1',
    icpLicenseUrl: 'https://beian.miit.gov.cn/',
    policeRecordNumber: '京公网安备11010502030123号',
    policeLicenseUrl: 'http://www.beian.gov.cn/portal/registerSystemInfo',
    recordInfoDisplay: 'footer',
    recordInfo: ''
  },
  
  // 安全设置数据
  securityConfig: {
    loginAttemptsLimit: 5,
    lockoutDuration: 15,
    sessionTimeout: 30,
    enableTwoFactorAuth: false,
    enableCaptcha: true
  }
};

// 模拟延迟函数
export const delay = (ms = 500) => {
  return new Promise(resolve => setTimeout(resolve, ms));
};

// 模拟API方法
export const mockApi = {
  // 登录
  login: async (credentials) => {
    await delay(800);
    if (credentials.username === mockData.loginCredentials.username && 
        credentials.password === mockData.loginCredentials.password) {
      return {
        code: 200,
        data: {
          token: mockData.token,
          username: credentials.username
        },
        message: '登录成功'
      };
    } else {
      return {
        code: 401,
        data: null,
        message: '用户名或密码错误'
      };
    }
  },
  
  // 刷新Token
  refreshToken: async (data) => {
    await delay(500);
    if (data.token === mockData.token) {
      return {
        code: 200,
        data: {
          token: mockData.token
        },
        message: '刷新成功'
      };
    } else {
      return {
        code: 401,
        data: null,
        message: 'Token无效或已过期'
      };
    }
  },
  
  // 检查登录状态
  checkLoginStatus: async () => {
    await delay(300);
    const token = localStorage.getItem('adminToken');
    if (token) {
      return {
        code: 200,
        data: {
          isLoggedIn: true,
          tokenValid: true,
          expiresAt: '2023-11-23T10:30:45Z'
        },
        message: 'success'
      };
    } else {
      return {
        code: 200,
        data: {
          isLoggedIn: false,
          tokenValid: false,
          expiresAt: null
        },
        message: 'success'
      };
    }
  },
  
  // 获取当前用户信息
  getCurrentUser: async () => {
    await delay(300);
    return {
      code: 200,
      data: {
        id: 1,
        username: 'admin',
        role: 'admin',
        permissions: ['all']
      },
      message: 'success'
    };
  },
  
  // 用户登出
  logout: async () => {
    await delay(500);
    localStorage.removeItem('adminToken');
    return {
      code: 200,
      data: null,
      message: '登出成功'
    };
  },
  
  // 获取仪表盘统计数据
  getDashboardStats: async () => {
    await delay(300);
    return {
      code: 200,
      data: mockData.dashboardStats,
      message: 'success'
    };
  },
  
  // 获取分类列表
  getCategories: async () => {
    await delay(300);
    return {
      code: 200,
      data: mockData.categories,
      message: 'success'
    };
  },
  
  // 添加分类
  addCategory: async (category) => {
    await delay(500);
    const newCategory = {
      id: mockData.categories.length + 1,
      name: category.name,
      count: 0
    };
    mockData.categories.push(newCategory);
    return {
      code: 200,
      data: newCategory,
      message: '添加成功'
    };
  },
  
  // 更新分类
  updateCategory: async (id, category) => {
    await delay(500);
    const index = mockData.categories.findIndex(c => c.id === id);
    if (index !== -1) {
      mockData.categories[index] = { ...mockData.categories[index], ...category };
      return {
        code: 200,
        data: mockData.categories[index],
        message: '更新成功'
      };
    }
    return {
      code: 404,
      data: null,
      message: '分类不存在'
    };
  },
  
  // 删除分类
  deleteCategory: async (id) => {
    await delay(500);
    const index = mockData.categories.findIndex(c => c.id === id);
    if (index !== -1) {
      mockData.categories.splice(index, 1);
      return {
        code: 200,
        data: null,
        message: '删除成功'
      };
    }
    return {
      code: 404,
      data: null,
      message: '分类不存在'
    };
  },
  
  // 获取标签列表
  getTags: async () => {
    await delay(300);
    return {
      code: 200,
      data: mockData.tags,
      message: 'success'
    };
  },
  
  // 添加标签
  addTag: async (tag) => {
    await delay(500);
    const newTag = {
      id: mockData.tags.length + 1,
      name: tag.name,
      count: 0
    };
    mockData.tags.push(newTag);
    return {
      code: 200,
      data: newTag,
      message: '添加成功'
    };
  },
  
  // 更新标签
  updateTag: async (id, tag) => {
    await delay(500);
    const index = mockData.tags.findIndex(t => t.id === id);
    if (index !== -1) {
      mockData.tags[index] = { ...mockData.tags[index], ...tag };
      return {
        code: 200,
        data: mockData.tags[index],
        message: '更新成功'
      };
    }
    return {
      code: 404,
      data: null,
      message: '标签不存在'
    };
  },
  
  // 删除标签
  deleteTag: async (id) => {
    await delay(500);
    const index = mockData.tags.findIndex(t => t.id === id);
    if (index !== -1) {
      mockData.tags.splice(index, 1);
      return {
        code: 200,
        data: null,
        message: '删除成功'
      };
    }
    return {
      code: 404,
      data: null,
      message: '标签不存在'
    };
  },
  
  // 获取文章列表
  getArticles: async (params = {}) => {
    await delay(500);
    let articles = [...mockData.articles];
    
    // 筛选
    if (params.categoryId) {
      articles = articles.filter(article => article.categoryId === params.categoryId);
    }
    if (params.tagId) {
      articles = articles.filter(article => article.tagIds.includes(params.tagId));
    }
    if (params.status) {
      articles = articles.filter(article => article.status === params.status);
    }
    if (params.keyword) {
      const keyword = params.keyword.toLowerCase();
      articles = articles.filter(article => 
        article.title.toLowerCase().includes(keyword) ||
        article.summary.toLowerCase().includes(keyword)
      );
    }
    
    // 排序
    if (params.sortBy === 'date') {
      articles.sort((a, b) => new Date(b.date) - new Date(a.date));
    }
    
    // 分页
    const page = params.page || 1;
    const pageSize = params.pageSize || 10;
    const startIndex = (page - 1) * pageSize;
    const endIndex = startIndex + pageSize;
    const paginatedArticles = articles.slice(startIndex, endIndex);
    
    return {
      code: 200,
      data: {
        list: paginatedArticles,
        total: articles.length,
        page,
        pageSize
      },
      message: 'success'
    };
  },
  
  // 获取文章详情
  getArticleDetail: async (id) => {
    await delay(400);
    const article = mockData.articles.find(a => a.id === parseInt(id));
    if (article) {
      // 模拟文章内容
      let content = '';
      if (article.id === 1) {
        content = `
          <h2>什么是组合式API？</h2>
          <p>组合式API (Composition API) 是Vue3中引入的一组新的API，它们允许我们以函数的方式组织和复用组件逻辑。</p>
          
          <h2>setup函数</h2>
          <p>setup函数是组合式API的入口点，它在组件实例创建之前执行。</p>
          
          <pre><code>export default {
            setup() {
              // 在这里使用组合式API
              return {}
            }
          }</code></pre>
        `;
      } else {
        content = `
          <h2>简介</h2>
          <p>${article.summary}</p>
          
          <h2>主要内容</h2>
          <p>这是一篇关于${article.title}的详细文章...</p>
        `;
      }
      
      return {
        code: 200,
        data: { ...article, content },
        message: 'success'
      };
    }
    return {
      code: 404,
      data: null,
      message: '文章不存在'
    };
  },
  
  // 添加文章
  addArticle: async (article) => {
    await delay(600);
    const newArticle = {
      id: mockData.articles.length + 1,
      ...article,
      date: new Date().toISOString().split('T')[0],
      views: 0
    };
    mockData.articles.unshift(newArticle);
    return {
      code: 200,
      data: newArticle,
      message: '添加成功'
    };
  },
  
  // 更新文章
  updateArticle: async (id, article) => {
    await delay(600);
    const index = mockData.articles.findIndex(a => a.id === parseInt(id));
    if (index !== -1) {
      mockData.articles[index] = { ...mockData.articles[index], ...article };
      return {
        code: 200,
        data: mockData.articles[index],
        message: '更新成功'
      };
    }
    return {
      code: 404,
      data: null,
      message: '文章不存在'
    };
  },
  
  // 删除文章
  deleteArticle: async (id) => {
    await delay(500);
    const index = mockData.articles.findIndex(a => a.id === parseInt(id));
    if (index !== -1) {
      mockData.articles.splice(index, 1);
      return {
        code: 200,
        data: null,
        message: '删除成功'
      };
    }
    return {
      code: 404,
      data: null,
      message: '文章不存在'
    };
  },
  
  // 获取个人信息
  getPersonalInfo: async () => {
    await delay(300);
    return {
      code: 200,
      data: mockData.personalInfo,
      message: 'success'
    };
  },
  
  // 更新个人信息
  updatePersonalInfo: async (info) => {
    await delay(500);
    mockData.personalInfo = { ...mockData.personalInfo, ...info };
    return {
      code: 200,
      data: mockData.personalInfo,
      message: '更新成功'
    };
  },
  
  // 图片相关API模拟方法
  
  // 获取图片列表
  getImages: async (params = {}) => {
    await delay(500);
    let images = [...mockData.images];
    
    // 筛选
    if (params.categoryId) {
      images = images.filter(image => image.categoryId?.toString() === params.categoryId.toString());
    }
    if (params.keyword) {
      const keyword = params.keyword.toLowerCase();
      images = images.filter(image => image.name.toLowerCase().includes(keyword));
    }
    
    // 排序
    if (params.sortBy === 'uploadDate') {
      images.sort((a, b) => new Date(b.uploadDate) - new Date(a.uploadDate));
    } else if (params.sortBy === 'size') {
      images.sort((a, b) => b.size - a.size);
    } else if (params.sortBy === 'name') {
      images.sort((a, b) => a.name.localeCompare(b.name));
    }
    
    // 分页
    const page = params.page || 1;
    const pageSize = params.pageSize || 12;
    const startIndex = (page - 1) * pageSize;
    const endIndex = startIndex + pageSize;
    const paginatedImages = images.slice(startIndex, endIndex);
    
    return {
      code: 200,
      data: {
        list: paginatedImages,
        total: images.length,
        page,
        pageSize
      },
      message: 'success'
    };
  },
  
  // 获取图片详情
  getImageDetail: async (id) => {
    await delay(400);
    const image = mockData.images.find(img => img.id === parseInt(id));
    if (image) {
      return {
        code: 200,
        data: image,
        message: 'success'
      };
    }
    return {
      code: 404,
      data: null,
      message: '图片不存在'
    };
  },
  
  // 上传图片
  uploadImage: async (formData) => {
    await delay(1000);
    
    // 模拟获取文件信息
    const file = formData.get('image');
    const categoryId = formData.get('categoryId');
    
    // 模拟获取目标分类
    let category = null;
    if (categoryId) {
      category = mockData.imageCategories.find(cat => cat.id.toString() === categoryId.toString());
    }
    
    // 更新分类计数
    if (category) {
      category.count++;
    }
    
    const newImage = {
      id: Date.now(),
      name: file.name,
      url: `https://example.com/images/${Date.now()}-${file.name}`,
      size: file.size,
      format: file.name.split('.').pop().toLowerCase(),
      width: 800, // 模拟值
      height: 600, // 模拟值
      uploadDate: new Date().toLocaleString('zh-CN'),
      categoryId: categoryId || null,
      category: category || null
    };
    
    mockData.images.unshift(newImage);
    
    return {
      code: 200,
      data: newImage,
      message: '上传成功'
    };
  },
  
  // 更新图片信息
  updateImage: async (id, image) => {
    await delay(500);
    const index = mockData.images.findIndex(img => img.id === parseInt(id));
    
    if (index !== -1) {
      // 处理分类变更
      let oldCategoryId = mockData.images[index].categoryId;
      let newCategoryId = image.categoryId;
      
      // 如果分类发生变化，更新计数
      if (oldCategoryId !== newCategoryId) {
        // 减少旧分类计数
        if (oldCategoryId) {
          const oldCategory = mockData.imageCategories.find(cat => cat.id.toString() === oldCategoryId.toString());
          if (oldCategory && oldCategory.count > 0) {
            oldCategory.count--;
          }
        }
        
        // 增加新分类计数
        if (newCategoryId) {
          const newCategory = mockData.imageCategories.find(cat => cat.id.toString() === newCategoryId.toString());
          if (newCategory) {
            newCategory.count++;
          }
        }
      }
      
      // 获取新分类信息
      let category = null;
      if (newCategoryId) {
        category = mockData.imageCategories.find(cat => cat.id.toString() === newCategoryId.toString());
      }
      
      mockData.images[index] = {
        ...mockData.images[index],
        ...image,
        category: category || null
      };
      
      return {
        code: 200,
        data: mockData.images[index],
        message: '更新成功'
      };
    }
    
    return {
      code: 404,
      data: null,
      message: '图片不存在'
    };
  },
  
  // 删除图片
  deleteImage: async (id) => {
    await delay(500);
    const index = mockData.images.findIndex(img => img.id === parseInt(id));
    
    if (index !== -1) {
      // 更新分类计数
      const categoryId = mockData.images[index].categoryId;
      if (categoryId) {
        const category = mockData.imageCategories.find(cat => cat.id.toString() === categoryId.toString());
        if (category && category.count > 0) {
          category.count--;
        }
      }
      
      mockData.images.splice(index, 1);
      
      return {
        code: 200,
        data: null,
        message: '删除成功'
      };
    }
    
    return {
      code: 404,
      data: null,
      message: '图片不存在'
    };
  },
  
  // 批量删除图片
  batchDeleteImages: async (ids) => {
    await delay(800);
    
    for (const id of ids) {
      const index = mockData.images.findIndex(img => img.id === parseInt(id));
      
      if (index !== -1) {
        // 更新分类计数
        const categoryId = mockData.images[index].categoryId;
        if (categoryId) {
          const category = mockData.imageCategories.find(cat => cat.id.toString() === categoryId.toString());
          if (category && category.count > 0) {
            category.count--;
          }
        }
        
        mockData.images.splice(index, 1);
      }
    }
    
    return {
      code: 200,
      data: null,
      message: '批量删除成功'
    };
  },
  
  // 批量移动图片
  batchMoveImages: async (ids, categoryId) => {
    await delay(600);
    
    // 获取目标分类
    let category = null;
    if (categoryId) {
      category = mockData.imageCategories.find(cat => cat.id.toString() === categoryId.toString());
    }
    
    for (const id of ids) {
      const index = mockData.images.findIndex(img => img.id === parseInt(id));
      
      if (index !== -1) {
        // 更新旧分类计数
        const oldCategoryId = mockData.images[index].categoryId;
        if (oldCategoryId && oldCategoryId !== categoryId) {
          const oldCategory = mockData.imageCategories.find(cat => cat.id.toString() === oldCategoryId.toString());
          if (oldCategory && oldCategory.count > 0) {
            oldCategory.count--;
          }
        }
        
        // 更新新分类计数
        if (categoryId && oldCategoryId !== categoryId) {
          if (category) {
            category.count++;
          }
        }
        
        // 更新图片分类
        mockData.images[index] = {
          ...mockData.images[index],
          categoryId: categoryId || null,
          category: category || null
        };
      }
    }
    
    return {
      code: 200,
      data: null,
      message: '批量移动成功'
    };
  },
  
  // 获取图片分类列表
  getImageCategories: async () => {
    await delay(300);
    return {
      code: 200,
      data: mockData.imageCategories,
      message: 'success'
    };
  },
  
  // 添加图片分类
  addImageCategory: async (category) => {
    await delay(500);
    const newCategory = {
      id: mockData.imageCategories.length + 1,
      name: category.name,
      count: 0
    };
    mockData.imageCategories.push(newCategory);
    
    return {
      code: 200,
      data: newCategory,
      message: '添加成功'
    };
  },
  
  // 更新图片分类
  updateImageCategory: async (id, category) => {
    await delay(500);
    const index = mockData.imageCategories.findIndex(cat => cat.id === parseInt(id));
    
    if (index !== -1) {
      mockData.imageCategories[index] = {
        ...mockData.imageCategories[index],
        ...category
      };
      
      // 更新相关图片的分类名称
      mockData.images.forEach(image => {
        if (image.categoryId === id) {
          image.category = {
            id: image.categoryId,
            name: mockData.imageCategories[index].name
          };
        }
      });
      
      return {
        code: 200,
        data: mockData.imageCategories[index],
        message: '更新成功'
      };
    }
    
    return {
      code: 404,
      data: null,
      message: '分类不存在'
    };
  },
  
  // 删除图片分类
  deleteImageCategory: async (id) => {
    await delay(500);
    const index = mockData.imageCategories.findIndex(cat => cat.id === parseInt(id));
    
    if (index !== -1) {
      // 检查分类下是否有图片
      const hasImages = mockData.images.some(image => image.categoryId === id);
      if (hasImages) {
        return {
          code: 400,
          data: null,
          message: '分类下有图片，无法删除'
        };
      }
      
      mockData.imageCategories.splice(index, 1);
      
      return {
        code: 200,
        data: null,
        message: '删除成功'
      };
    }
    
    return {
      code: 404,
      data: null,
      message: '分类不存在'
    };
  },
  
  // 获取系统配置
  getSystemConfig: async () => {
    await delay(300);
    return {
      code: 200,
      data: mockData.systemConfig,
      message: 'success'
    };
  },
  
  // 更新系统配置
  updateSystemConfig: async (config) => {
    await delay(500);
    mockData.systemConfig = { ...mockData.systemConfig, ...config };
    return {
      code: 200,
      data: mockData.systemConfig,
      message: '更新成功'
    };
  },
  
  // 获取ICP备案配置
  getIcpConfig: async () => {
    await delay(300);
    return {
      code: 200,
      data: mockData.icpConfig,
      message: 'success'
    };
  },
  
  // 更新ICP备案配置
  updateIcpConfig: async (config) => {
    await delay(500);
    mockData.icpConfig = { ...mockData.icpConfig, ...config };
    return {
      code: 200,
      data: mockData.icpConfig,
      message: '更新成功'
    };
  },
  
  // 获取安全设置
  getSecurityConfig: async () => {
    await delay(300);
    return {
      code: 200,
      data: mockData.securityConfig,
      message: 'success'
    };
  },
  
  // 更新安全设置
  updateSecurityConfig: async (config) => {
    await delay(500);
    mockData.securityConfig = { ...mockData.securityConfig, ...config };
    return {
      code: 200,
      data: mockData.securityConfig,
      message: '更新成功'
    };
  }
};
